-
Notifications
You must be signed in to change notification settings - Fork 35
[CTL] Add support for defaults #1320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
test/ctl/ctl_api.cpp
Outdated
umfDisjointPoolParamsDestroy(params); | ||
} catch (Pool::CtlException &e) { | ||
umfDisjointPoolParamsDestroy(params); | ||
GTEST_SKIP() << e.what(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why skip, can't we fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is commonly used in our tests:
ctest --verbose | grep SKIP | wc -l
295
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in some cases SKIP is acceptable, here I believe occurence of CtlException may be caused by a real issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed CtlException completely
test/pools/disjoint_pool.cpp
Outdated
umf_memory_provider_handle_t provider_handle = nullptr; | ||
umf_memory_pool_handle_t pool = NULL; | ||
|
||
struct memory_provider : public umf_test::provider_base_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this struct in this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be reworked separately. It follows the approach used in the disjoint pool tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so pls leave the struct but don't add the dead code which is the body of the struct with redundant functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed boilerplate.
test/pools/disjoint_pool_ctl.cpp
Outdated
auto res = umfPoolCreate(m_poolOps, m_provider, m_params, 0, &m_pool); | ||
if (res != UMF_RESULT_SUCCESS) { | ||
m_pool = nullptr; | ||
LOG_ERR("Failed to create memory pool"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if LOG in test is expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, if you still want to print some error msg in tests you can just use printf or something..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe unit tests should not print logs.
src/libumf.c
Outdated
|
||
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg, size_t size) { | ||
if (name == NULL || arg == NULL) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ, | ||
arg, size); | ||
} | ||
|
||
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size) { | ||
// Context can be NULL when setting defaults | ||
if (name == NULL || arg == NULL || size == 0) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE, | ||
arg, size) | ||
? UMF_RESULT_ERROR_UNKNOWN | ||
: UMF_RESULT_SUCCESS; | ||
} | ||
|
||
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) { | ||
if (name == NULL || arg == NULL || ctx == NULL) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, | ||
CTL_QUERY_RUNNABLE, arg, size) | ||
? UMF_RESULT_ERROR_UNKNOWN | ||
: UMF_RESULT_SUCCESS; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is chaos in this inval check - please add comment per each function why we not check for null.
For sure exec should accept null arg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/memory_pool.c
Outdated
if (ctx && strstr(extra_name, "default")) { | ||
utils_mutex_unlock(&ctl_mtx); | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this strstr? If yes what we are looking for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -22,13 +22,13 @@ | |||
#include "utils_assert.h" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is support for defaults for memory providers? I see only implementation for pools, and we need both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be splitted between 2 PR's
include/umf/memory_pool_ops.h
Outdated
/// @brief Retrieves the name of the disjoint memory pool [optional] | ||
/// @param pool pointer to the memory pool or NULL value | ||
/// @return A constant character string representing the pool's name. | ||
/// Returns "disjoint" if `pool` is NULL, otherwise returns the | ||
/// configured name of the specific pool instance. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document requirements of interface - not how this function behaviors for disjoint pool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ctl/ctl.h
Outdated
/* | ||
* Declaration of a new RW leaf. This type of RW leaf doesn't require parsing | ||
* of the argument. The argument is passed directly to the read/write callback. | ||
*/ | ||
#define CTL_LEAF_RW_no_arg(name, ...) \ | ||
{ \ | ||
CTL_STR(name), CTL_NODE_LEAF, \ | ||
{CTL_READ_HANDLER(name, __VA_ARGS__), \ | ||
CTL_WRITE_HANDLER(name, __VA_ARGS__), NULL, NULL}, \ | ||
NULL, NULL \ | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, done.
test/ctl/ctl_unittest.cpp
Outdated
@@ -21,35 +21,35 @@ TEST_F(test, ctl_debug_read_from_string) { | |||
|
|||
int value = 0; | |||
ctl_query(ctl_handler, NULL, CTL_QUERY_PROGRAMMATIC, | |||
"debug.heap.alloc_pattern", CTL_QUERY_READ, &value); | |||
"debug.heap.alloc_pattern", CTL_QUERY_READ, &value, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my comment from the prev. PR is not resolved:
whenever size is used, please add a test with various values (user may give some input we may not expect, e.g. on wrong assumptions on how this func works) or mark a TODO for adding tests in the future
e.g. here you can simply add a repeated queries with non-zero values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
3dbf762
to
c43ddc7
Compare
aec5266
to
fe4e66f
Compare
/// | ||
/// @brief Retrieve name of a given memory \p pool. | ||
/// @param pool handle to the memory pool | ||
/// @return pointer to a string containing the name of the \p pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, or NULL when ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/// @param operationType type of the operation to be performed. | ||
/// @param name name associated with the operation. | ||
/// @param arg argument for the operation. | ||
/// @param size size of the argument [optional - check path requirements] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant english word "context" not a parameter called context
; nontheless, IMHO, this is still ambiguous - I'm really not sure what/where should I check
include/umf/memory_provider_ops.h
Outdated
@@ -259,12 +259,13 @@ typedef struct umf_memory_provider_ops_t { | |||
/// @param operationType type of the operation to be performed. | |||
/// @param name name associated with the operation. | |||
/// @param arg argument for the operation. | |||
/// @param size size of the argument [optional - check path requirements] | |||
/// @param queryType type of the query to be performed. | |||
/// | |||
/// @return umf_result_t result of the control operation. | |||
/// | |||
umf_result_t (*ctl)(void *hProvider, int operationType, const char *name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few lines above in the review we can see the change hPool
-> pool
; similarly here hProvider
-> provider
// it's just a nit
test/ctl/ctl_api.cpp
Outdated
umfDisjointPoolParamsDestroy(params); | ||
} catch (Pool::CtlException &e) { | ||
umfDisjointPoolParamsDestroy(params); | ||
GTEST_SKIP() << e.what(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in some cases SKIP is acceptable, here I believe occurence of CtlException may be caused by a real issue
test/pools/disjoint_pool.cpp
Outdated
umf_memory_provider_handle_t provider_handle = nullptr; | ||
umf_memory_pool_handle_t pool = NULL; | ||
|
||
struct memory_provider : public umf_test::provider_base_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so pls leave the struct but don't add the dead code which is the body of the struct with redundant functions
// umfCtlGet - invalid arg | ||
res = umfCtlGet(valid_path, valid_ctx, NULL, strlen(valid_arg)); | ||
ASSERT_EQ(res, UMF_RESULT_ERROR_INVALID_ARGUMENT); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have invalid ctx as well? (not sure if this makes sense or not)
test/pools/disjoint_pool_ctl.cpp
Outdated
auto res = umfPoolCreate(m_poolOps, m_provider, m_params, 0, &m_pool); | ||
if (res != UMF_RESULT_SUCCESS) { | ||
m_pool = nullptr; | ||
LOG_ERR("Failed to create memory pool"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, if you still want to print some error msg in tests you can just use printf or something..
|
||
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) { | ||
// arg can be NULL when executing a command | ||
// ctx can be NULL when executing defaults |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx can be NULL but you return UMF_RESULT_ERROR_INVALID_ARGUMENT?
additionally, it looks like we don't have a test for this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, fixed
src/memory_pool.c
Outdated
const char *extra_name, | ||
umf_ctl_query_type_t queryType) { | ||
(void)indexes, (void)source; | ||
if (ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do you use ctx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because the exec can also go through this path
Description
Checklist